import { defineFakeRoute } from 'vite-plugin-fake-server/client'

// 导航
const menuList = [
  {
    id: 1,
    parentId: 0,
    meta: {
      title: '演示',
      icon: 'uim:box',
      activeIcon: '',
      auth: [],
      auths: [],
    },
    children: [
      {
        id: 2,
        parentId: 1,
        path: '/multilevel_menu_example',
        redirect: '/multilevel_menu_example/page',
        component: 'Layout',
        name: 'multilevelMenuExample',
        meta: {
          title: '多级导航',
          icon: 'heroicons-solid:menu-alt-3',
          activeIcon: '',
          defaultOpened: false,
          alwaysOpened: false,
          permanent: false,
          auth: [],
          auths: [
            {
              name: '测试权限1',
              value: 'test1',
            },
            {
              name: '测试权限2',
              value: 'test2',
            },
            {
              name: '测试权限3',
              value: 'test3',
            },
          ],
          menu: true,
          breadcrumb: true,
          activeMenu: '',
          cache: [],
          noCache: [],
          badge: '',
          badgeVariant: 'default',
          newWindow: false,
          link: '',
          iframe: '',
          copyright: false,
        },
        children: [
          {
            id: 3,
            parentId: 2,
            path: 'page',
            redirect: '',
            component: 'multilevel_menu_example/page.vue',
            name: 'multilevelMenuExample1',
            meta: {
              title: '导航1',
              icon: '',
              activeIcon: '',
              defaultOpened: false,
              alwaysOpened: false,
              permanent: false,
              auth: [],
              auths: [],
              menu: true,
              breadcrumb: true,
              activeMenu: '',
              cache: [],
              noCache: [],
              badge: '',
              badgeVariant: 'default',
              newWindow: false,
              link: '',
              iframe: '',
              copyright: false,
            },
          },
          {
            id: 4,
            parentId: 2,
            path: 'level2',
            name: 'multilevelMenuExample2',
            redirect: '/multilevel_menu_example/level2/page',
            meta: {
              title: '导航2',
              icon: '',
              activeIcon: '',
              defaultOpened: false,
              alwaysOpened: false,
              permanent: false,
              auth: [],
              auths: [],
              menu: true,
              breadcrumb: true,
              activeMenu: '',
              cache: [],
              noCache: [],
              badge: '',
              badgeVariant: 'default',
              newWindow: false,
              link: '',
              iframe: '',
              copyright: false,
            },
            children: [
              {
                id: 5,
                parentId: 4,
                path: 'page',
                name: 'multilevelMenuExample2-1',
                component: 'multilevel_menu_example/level2/page.vue',
                meta: {
                  title: '导航2-1',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: '',
                  copyright: false,
                },
              },
              {
                id: 6,
                parentId: 4,
                path: 'level3',
                name: 'multilevelMenuExample2-2',
                redirect: '/multilevel_menu_example/level2/level3/page1',
                meta: {
                  title: '导航2-2',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: '',
                  copyright: false,
                },
                children: [
                  {
                    id: 7,
                    parentId: 6,
                    path: 'page1',
                    name: 'multilevelMenuExample2-2-1',
                    component: 'multilevel_menu_example/level2/level3/page1.vue',
                    meta: {
                      title: '导航2-2-1',
                      icon: '',
                      activeIcon: '',
                      defaultOpened: false,
                      alwaysOpened: false,
                      permanent: false,
                      auth: [],
                      auths: [],
                      menu: true,
                      breadcrumb: true,
                      activeMenu: '',
                      cache: [],
                      noCache: [],
                      badge: '',
                      badgeVariant: 'default',
                      newWindow: false,
                      link: '',
                      iframe: '',
                      copyright: false,
                    },
                  },
                  {
                    id: 8,
                    parentId: 6,
                    path: 'page2',
                    name: 'multilevelMenuExample2-2-2',
                    component: 'multilevel_menu_example/level2/level3/page2.vue',
                    meta: {
                      title: '导航2-2-2',
                      icon: '',
                      activeIcon: '',
                      defaultOpened: false,
                      alwaysOpened: false,
                      permanent: false,
                      auth: [],
                      auths: [],
                      menu: true,
                      breadcrumb: true,
                      activeMenu: '',
                      cache: [],
                      noCache: [],
                      badge: '',
                      badgeVariant: 'default',
                      newWindow: false,
                      link: '',
                      iframe: '',
                      copyright: false,
                    },
                  },
                ],
              },
            ],
          },
        ],
      },
      {
        id: 9,
        parentId: 1,
        path: '/link',
        component: 'Layout',
        redirect: '/link/iframe',
        name: 'externalLinkExample',
        meta: {
          title: '外链',
          icon: 'ri:external-link-fill',
          activeIcon: '',
          defaultOpened: false,
          alwaysOpened: false,
          permanent: false,
          auth: [],
          auths: [],
          menu: true,
          breadcrumb: true,
          activeMenu: '',
          cache: [],
          noCache: [],
          badge: '',
          badgeVariant: 'default',
          newWindow: false,
          link: '',
          iframe: '',
          copyright: false,
        },
        children: [
          {
            id: 10,
            parentId: 9,
            path: 'iframe',
            redirect: '/link/iframe/iframeVue',
            meta: {
              title: '内嵌 Iframe',
              icon: '',
              activeIcon: '',
              defaultOpened: false,
              alwaysOpened: false,
              permanent: false,
              auth: [],
              auths: [],
              menu: true,
              breadcrumb: true,
              activeMenu: '',
              cache: [],
              noCache: [],
              badge: '',
              badgeVariant: 'default',
              newWindow: false,
              link: '',
              iframe: '',
              copyright: false,
            },
            children: [
              {
                id: 11,
                parentId: 10,
                path: 'iframeVue',
                redirect: '',
                name: 'linkExampleIframeVue',
                meta: {
                  title: 'Vue 官方文档',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: true,
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: 'https://cn.vuejs.org/',
                  copyright: false,
                },
              },
              {
                id: 12,
                parentId: 10,
                path: 'iframeElement',
                redirect: '',
                name: 'linkExampleIframeElement',
                meta: {
                  title: 'Element Plus 官方文档',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: true,
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: 'https://element-plus.org/zh-CN/',
                  copyright: false,
                },
              },
              {
                id: 13,
                parentId: 10,
                path: 'iframeVueRouter',
                redirect: '',
                name: 'linkExampleIframeVueRouter',
                meta: {
                  title: 'Vue-Router 官方文档',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: true,
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: 'https://router.vuejs.org/zh/',
                  copyright: false,
                },
              },
              {
                id: 14,
                parentId: 10,
                path: 'iframeVuePinia',
                redirect: '',
                name: 'linkExampleIframeVuePinia',
                meta: {
                  title: 'Pinia 官方文档',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: true,
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: 'https://pinia.vuejs.org/zh/',
                  copyright: false,
                },
              },
            ],
          },
          {
            id: 15,
            parentId: 9,
            path: 'window',
            redirect: '/link/window/gitee',
            meta: {
              title: '新窗口打开',
              icon: '',
              activeIcon: '',
              defaultOpened: false,
              alwaysOpened: false,
              permanent: false,
              auth: [],
              auths: [],
              menu: true,
              breadcrumb: true,
              activeMenu: '',
              cache: [],
              noCache: [],
              badge: '',
              badgeVariant: 'default',
              newWindow: false,
              link: '',
              iframe: '',
              copyright: false,
            },
            children: [
              {
                id: 16,
                parentId: 15,
                path: 'gitee',
                redirect: '',
                name: 'linkExampleWindowGitee',
                meta: {
                  title: 'Gitee 仓库',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: 'https://gitee.com/fantastic-admin/basic',
                  iframe: '',
                  copyright: false,
                },
              },
              {
                id: 17,
                parentId: 15,
                path: 'github',
                redirect: '',
                name: 'linkExampleWindowGithub',
                meta: {
                  title: 'Github 仓库',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [],
                  auths: [],
                  menu: true,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: 'https://github.com/fantastic-admin/basic',
                  iframe: '',
                  copyright: false,
                },
              },
            ],
          },
        ],
      },
    ],
  },
  {
    id: 50,
    parentId: 0,
    meta: {
      title: '页面',
      i18n: '',
      icon: 'ri:pages-line',
      activeIcon: '',
      auth: [],
      auths: [],
    },
    children: [
      {
        id: 51,
        parentId: 50,
        path: '/pages_example/general',
        component: 'Layout',
        redirect: '/pages_example/general/manager',
        name: 'pagesExampleGeneral',
        meta: {
          title: '通用',
          icon: '',
          activeIcon: '',
          defaultOpened: false,
          alwaysOpened: false,
          permanent: false,
          auth: [],
          auths: [],
          menu: true,
          breadcrumb: true,
          activeMenu: '',
          cache: [],
          noCache: [],
          badge: '',
          badgeVariant: 'default',
          newWindow: false,
          link: '',
          iframe: '',
          copyright: false,
        },
        children: [
          {
            id: 52,
            parentId: 51,
            path: 'manager',
            name: 'pagesExampleGeneralManager',
            redirect: '/pages_example/general/manager',
            meta: {
              title: '管理员管理',
              icon: '',
              activeIcon: '',
              defaultOpened: false,
              alwaysOpened: false,
              permanent: false,
              auth: [],
              auths: [
                {
                  name: '浏览',
                  value: 'manager.browse',
                },
                {
                  name: '新增',
                  value: 'manager.create',
                },
                {
                  name: '编辑',
                  value: 'manager.edit',
                },
                {
                  name: '删除',
                  value: 'manager.delete',
                },
              ],
              menu: true,
              breadcrumb: true,
              activeMenu: '',
              cache: [],
              noCache: [],
              badge: '',
              badgeVariant: 'default',
              newWindow: false,
              link: '',
              iframe: '',
              copyright: false,
            },
            children: [
              {
                id: 53,
                parentId: 52,
                path: '',
                name: 'pagesExampleGeneralManagerList',
                component: 'pages_example/manager/list.vue',
                meta: {
                  title: '管理员列表',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [
                    'manager.browse',
                  ],
                  auths: [],
                  menu: false,
                  breadcrumb: false,
                  activeMenu: '',
                  cache: [
                    'pagesExampleGeneralManagerCreate',
                    'pagesExampleGeneralManagerEdit',
                  ],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: '',
                  copyright: false,
                },
              },
              {
                id: 53,
                parentId: 52,
                path: 'detail',
                name: 'pagesExampleGeneralManagerCreate',
                component: 'pages_example/manager/detail.vue',
                meta: {
                  title: '新增管理员',
                  icon: '',
                  activeIcon: '/pages_example/general/manager',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [
                    'manager.create',
                  ],
                  auths: [],
                  menu: false,
                  breadcrumb: true,
                  activeMenu: '',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: '',
                  copyright: false,
                },
              },
              {
                id: 54,
                parentId: 52,
                path: 'detail/:id',
                name: 'pagesExampleGeneralManagerEdit',
                component: 'pages_example/manager/detail.vue',
                meta: {
                  title: '编辑管理员',
                  icon: '',
                  activeIcon: '',
                  defaultOpened: false,
                  alwaysOpened: false,
                  permanent: false,
                  auth: [
                    'manager.edit',
                  ],
                  auths: [],
                  menu: false,
                  breadcrumb: true,
                  activeMenu: '/pages_example/general/manager',
                  cache: [],
                  noCache: [],
                  badge: '',
                  badgeVariant: 'default',
                  newWindow: false,
                  link: '',
                  iframe: '',
                  copyright: false,
                },
              },
            ],
          },
        ],
      },
    ],
  },
]

export default defineFakeRoute([
  {
    url: '/mock/menu/list',
    method: 'get',
    response: () => {
      return {
        error: '',
        status: 1,
        data: menuList,
      }
    },
  },
  {
    url: '/mock/menu/detail',
    method: 'get',
    response: ({ query }) => {
      function findMenu(list: any, id: number): any {
        for (const i in list) {
          if (list[i].id === id) {
            const retn = {
              ...list[i],
            }
            delete retn.children
            return retn
          }
          else if (list[i].children) {
            const temp = findMenu(list[i].children, id)
            if (temp) {
              return temp
            }
          }
        }
      }
      const info = findMenu(menuList, ~~query.id)
      return {
        error: '',
        status: 1,
        data: info,
      }
    },
  },
  {
    url: '/mock/menu/create',
    method: 'post',
    response: () => {
      return {
        error: '',
        status: 1,
        data: {
          isSuccess: true,
        },
      }
    },
  },
  {
    url: '/mock/menu/edit',
    method: 'post',
    response: () => {
      return {
        error: '',
        status: 1,
        data: {
          isSuccess: true,
        },
      }
    },
  },
  {
    url: '/mock/menu/delete',
    method: 'post',
    response: () => {
      return {
        error: '',
        status: 1,
        data: {
          isSuccess: true,
        },
      }
    },
  },
])
